/*
 * @lc app=leetcode.cn id=206 lang=javascript
 *
 * [206] 反转链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var reverseList = function(head) {
    function reverse(prev,cur){
        if(cur==null){return prev}
        let temp=cur.next
        cur.next=prev
        return reverse(cur,temp)
    }
    return reverse(null,head)
};
// @lc code=end

var reverseList = function(head) {
    let prev=null//这个很关键，补充后面指向的null
    let cur=head
    while(cur){
        let temp=cur.next
        cur.next=prev
        prev=cur
        cur=temp
    }
    return prev
};//迭代